<?php
header ( 'Content-type: application/excel' );
header ( 'Content-Disposition: attachment; filename="data.xlsx"' );
echo '<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?>';
?>
<Workbook xmlns:x="urn:schemas-microsoft-com:office:excel"
	  xmlns="urn:schemas-microsoft-com:office:spreadsheet"
	  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
    <ss:Styles>
        <ss:Style ss:ID="Date"><ss:NumberFormat ss:Format="Short Date"></ss:NumberFormat></ss:Style>
        <ss:Style ss:ID="Standard"><ss:NumberFormat ss:Format="Standard"></ss:NumberFormat></ss:Style>
    </ss:Styles>
    <Worksheet ss:Name="<?php echo $this->meta['title'] ?>" ss:Description="<?php echo $this->translate("Description") ?>">
        <ss:Table>
            <ss:Row>
                <?php foreach($this->meta['headers'] as $col) : ?>
                <ss:Cell><Data ss:Type="String"><?php echo $col[2] ?></Data></ss:Cell>
                <?php endforeach ?>
            </ss:Row>
            <?php foreach($this->data as $row) : ?>
            <ss:Row>
                <?php foreach ( $this->meta['headers'] as $col ) : ?>
                <ss:Cell<?php echo isset($col[4]) ? ' ss:StyleID="'.$col[4].'"' : '' ?>>
                    <?php if($col[3] == 'DateTime') : ?>
                    <?php $row[$col[0]] = str_replace(' ','T',$row[$col[0]]); ?>
                    <?php endif ?>
                    <Data ss:Type="<?php echo $col[3] ?>"><?php echo $row[$col[0]] ? $this->escape($this->translate($row[$col[0]])) : '' ?></Data>
                </ss:Cell>
                <?php endforeach ?>
            </ss:Row>
            <?php endforeach ?>
        </ss:Table>
    </Worksheet>
</Workbook>
<?php exit; ?>